﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace STS
{
    /// <summary>
    /// Summary description for Obraz
    /// </summary>
    public class Obraz : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
                 string id = context.Request.QueryString["Id"];
              context.Response.ContentType = "image/jpeg";
                Stream strm = ShowEmpImage(id);
                byte[] buffer = new byte[4096];
                int byteSeq = strm.Read(buffer, 0, 4096);
                while (byteSeq > 0)
                {
                    context.Response.OutputStream.Write(buffer, 0, byteSeq);
                    byteSeq = strm.Read(buffer, 0, 4096);
                }  
        }

        public Stream ShowEmpImage(string id)
          {
                baza db = new baza();
                var r = (from a in db.badanias where a.id_badania == Convert.ToInt32(id) select a).First();
                return new MemoryStream(r.obraz.ToArray());         
    
            }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}